package com.huike.business.service.impl;


import com.huike.business.domain.TbBusiness;
import com.huike.business.domain.TbBusinessTrackRecord;
import com.huike.business.domain.vo.BusinessTrackVo;
import com.huike.business.mapper.TbBusinessMapper;
import com.huike.business.mapper.TbBusinessTrackRecordMapper;
import com.huike.business.service.ITbBusinessTrackRecordService;
import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Properties;

/**
 * 商机跟进记录Service业务层处理
 * 
 * @author wgl
 * @date 2021-04-28
 */
@Service
public class TbBusinessTrackRecordServiceImpl implements ITbBusinessTrackRecordService {

    @Autowired
    private TbBusinessTrackRecordMapper tbBusinessTrackRecordMapper;

    @Autowired
    private TbBusinessMapper tbBusinessMapper;

    @Override
    public void add(BusinessTrackVo businessTrackVo) {
        /**
         * 添加商机跟进记录
         * @param
         */
        //创建一个商机跟进对象
        TbBusinessTrackRecord tbBusinessTrackRecord = new TbBusinessTrackRecord();
        //把前端传过来的对象进行拷贝封装
        BeanUtils.copyProperties(businessTrackVo, tbBusinessTrackRecord);
        //通过工具列获取当前创建人并设置
        tbBusinessTrackRecord.setCreateBy(SecurityUtils.getUsername());
        //设置创建时间
        tbBusinessTrackRecord.setCreateTime(new Date());

        TbBusiness tbBusiness = new TbBusiness();
        BeanUtils.copyProperties(businessTrackVo,tbBusiness);
        //调用方法修改商机
        tbBusiness.setStatus(TbClue.StatusType.FOLLOWING.getValue());
        tbBusinessMapper.updateTbBusiness(tbBusiness);

        //调用方法添加商机跟进对象
        tbBusinessTrackRecordMapper.add(tbBusinessTrackRecord);
        }

    @Override
    public List<TbBusinessTrackRecord> selectList(Long id) {
        return tbBusinessTrackRecordMapper.selectList(id);
    }
}
